import { createSlice } from "@reduxjs/toolkit";
import instance from '../axios/index'


const cartSlice = createSlice({
    name: "cart",
    initialState: {
        useList: {
            title: '',
            url: '',
            jifen: 0,
        },

    },
    reducers: {
        modify(state, action) {
            const data = action.payload
            if (state.useList.title == '' && state.useList.url == '' && state.useList.jifen == 0) {
                state.useList.title = data.name
                state.useList.url = data.avater
            }else{
                return
            }
        },
        selectTitle(state, action) {
            const title = action.payload
            state.useList.title = title
        },
        selectUrl(state, action) {
            const url = action.payload
            state.useList.url = url
        },
        selectJifen(state, action) {
            const jifen = action.payload
            state.useList.jifen = jifen
        }
    }
})


export const { modify, selectTitle, selectUrl, selectJifen } = cartSlice.actions;


export default cartSlice.reducer;